<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../../../component/pear/css/pear.css"/>
</head>
<body>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
                <!--学号-->
                <div class="layui-form-item">
                    <label class="layui-form-label">学号</label>
                    <div class="layui-input-block">
                        <input id="userId" type="text" name="userId" value="" lay-verify="title"
                               autocomplete="off"
                               placeholder="请输入学号" class="layui-input"
                               style="cursor:not-allowed;color: #a1a1a1;" disabled>
                    </div>
                </div>
                <!--姓名-->
                <div class="layui-form-item">
                    <label class="layui-form-label">姓名</label>
                    <div class="layui-input-block">
                        <input id="realName" type="text" name="realName" lay-verify="required" autocomplete="off"
                               placeholder="请输入姓名"
                               class="layui-input" lay-reqText="请输入姓名">
                    </div>
                </div>
                <!--专业-->
                <div class="layui-form-item">
                    <label class="layui-form-label">专业</label>
                    <div class="layui-input-block">
                        <select id="major" name="major" lay-verify="required"
                                lay-search lay-reqText="请选择专业">
                        </select>
                    </div>
                </div>
                <!--学历层次-->
                <div class="layui-form-item">
                    <label class="layui-form-label">学历层次</label>
                    <div class="layui-input-block">
                        <select name="levels" lay-verify="">
                            <option id="level01" value="专科">专科</option>
                            <option id="level02" value="本科">本科</option>
                            <option id="level03" value="硕士">硕士</option>
                            <option id="level04" value="博士">博士</option>
                        </select>
                    </div>
                </div>
                <!--班级-->
                <div class="layui-form-item">
                    <label class="layui-form-label">班级</label>
                    <div class="layui-input-block">
                        <input id="classes" type="text" name="classes" lay-verify="required" autocomplete="off"
                               placeholder="请输入班级"
                               class="layui-input" lay-reqText="请输入班级">
                    </div>
                </div>
                <!--家庭住址-->
                <div class="layui-form-item">
                    <label class="layui-form-label">家庭住址</label>
                    <div class="layui-input-block">
                        <input id="addr" type="text" name="addr" lay-verify="required" autocomplete="off"
                               placeholder="请输入学生家庭住址"
                               class="layui-input" lay-reqText="请输入学生家庭住址">
                    </div>
                </div>

                <!--电话-->
                <div class="layui-form-item">
                    <label class="layui-form-label">电话</label>
                    <div class="layui-input-block">
                        <input id="phone" type="text" name="phone" value="" lay-verify="required|phone"
                               autocomplete="off"
                               placeholder="请输入手机号码" class="layui-input" lay-reqText="请输入手机号码">
                    </div>
                </div>
                <!--性别-->
                <div class="layui-form-item">
                    <label class="layui-form-label">性别</label>
                    <div class="layui-input-block">
                        <input id="man" type="radio" name="sex" value="1" title="男">
                        <input id="woman" type="radio" name="sex" value="2" title="女" checked>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="" lay-filter="user-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
        </div>
    </div>
</form>
<script src="../../../component/layui/layui.js"></script>
<script src="../../../component/pear/pear.js"></script>
<script>
    layui.use(['form', 'jquery'], function () {
        let form = layui.form;
        let $ = layui.jquery;
        //$("#userId").val(parent.obj.data['userId']);
        // console.log(parent.layui.table)

        //从服务器加载专业列表
        $.ajax({
            url: '/Major/getMajors',
            dataType: 'json',
            type: 'post',
            success: function (res) {
                console.log(res.data);
                let major = $('#major');
                major.append('<option value="">请选择专业</option>')
                for (let i = 0; i < res.data.length; i++) {
                    let majorName = res.data[i].majorName;
                    major.append('<option value="' + majorName + '">' + majorName + '</option>')
                }
                form.render('select');
            }
        })


        form.on('submit(user-save)', function (data) {
            let index = layer.load(2, {time: 10 * 1000}); //又换了种风格，并且设定最长等待10秒
            $.ajax({
                url: '/admin/stu/updateStudent',
                data: data.field,
                dataType: 'json',
                contentType: 'application/json',
                type: 'get',
                success: function (result) {
                    layer.close(index);
                    if (result.success) {
                        layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            //console.log(parent.layui.jquery(".layui-laypage-em").next().html());
                            parent.layui.table.reload("user-table", {
                                data: result.data,
                                page: {
                                    layout: ['count', 'prev', 'page', 'next', 'skip']
                                    , curr: parent.layui.jquery(".layui-laypage-em").next().html()
                                    , groups: 3
                                    , last: false
                                }
                            });
                        });
                    } else {
                        layer.msg(result.msg, {icon: 2, time: 1000});
                    }
                }
            })
            return false;
        });
    })
</script>
<script>
</script>
</body>
</html>
